package com.example.reactor;

import reactor.core.publisher.Flux;

import java.time.Duration;

public class Practice8 {

    public static void main(String[] args) {

        Flux.merge(Flux.interval(Duration.ofMillis(100)).take(5),
                        Flux.interval(Duration.ofMillis(100)).take(3))
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.mergeSequential(Flux.interval(Duration.ofMillis(100)).take(5),
                        Flux.interval(Duration.ofMillis(100)).take(3))
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.range(1, 10)
                .buffer(3, 3)
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.interval(Duration.ofMillis(100L))
                .bufferTimeout(9, Duration.ofMillis(1000L))
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.range(1, 10)
                .bufferWhile(i -> i % 2 == 0)
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.range(1, 10)
                .bufferUntil(i -> i % 2 == 0, false)
                .subscribe(System.out::println);


        while (true) {
            try {
                Thread.sleep(10000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }


}
